#include "advicewindow.h"
#include <QVBoxLayout>

AdviceWindow::AdviceWindow(QWidget *parent) : QMainWindow(parent)
{
    setWindowTitle("💡 健康建议 💡");
    resize(600, 500);
    setStyleSheet("background-color: #f8f9fa;");
    
    adviceText = new QTextEdit(this);
    adviceText->setReadOnly(true);
    adviceText->setStyleSheet(
        "QTextEdit {"
        "  font-size: 14pt;"
        "  background-color: white;"
        "  border: 2px solid #dee2e6;"
        "  border-radius: 15px;"
        "  padding: 15px;"
        "}"
    );

    backButton = new QPushButton("🔙 返回", this);
    backButton->setStyleSheet(
        "QPushButton {"
        "  font-size: 14pt;"
        "  padding: 12px 24px;"
        "  background-color: #adb5bd;"
        "  color: white;"
        "  border-radius: 15px;"
        "  border: none;"
        "}"
        "QPushButton:hover {"
        "  background-color: #6c757d;"
        "}"
    );

    aiChatButton = new QPushButton("🤖 AI详细咨询", this);
    aiChatButton->setStyleSheet(
        "QPushButton {"
        "  font-size: 14pt;"
        "  padding: 12px 24px;"
        "  background-color: #4cc9f0;"
        "  color: white;"
        "  border-radius: 15px;"
        "  border: none;"
        "}"
        "QPushButton:hover {"
        "  background-color: #4895ef;"
        "}"
    );

    QHBoxLayout *buttonLayout = new QHBoxLayout();
    buttonLayout->addWidget(backButton);
    buttonLayout->addStretch();
    buttonLayout->addWidget(aiChatButton);

    QVBoxLayout *layout = new QVBoxLayout();
    layout->addWidget(adviceText);
    layout->addLayout(buttonLayout);

    aiChatDialog = new AIChatDialog(this);
    connect(aiChatButton, &QPushButton::clicked, [this]() {
        aiChatDialog->setInitialPrompt(adviceText->toPlainText());
        aiChatDialog->show();
    });

    QWidget *centralWidget = new QWidget(this);
    centralWidget->setLayout(layout);
    setCentralWidget(centralWidget);

    connect(backButton, &QPushButton::clicked, this, &AdviceWindow::returnToPrevious);
}

void AdviceWindow::setAdviceText(const QString &text)
{
    adviceText->setHtml(QString("<h3>健康建议</h3><p>%1</p>").arg(text));
}